from PySide6.QtWidgets import QApplication, QMessageBox, QMainWindow
from PySide6.QtUiTools import QUiLoader
from ui_main import Ui_MainWindow
import requests
class Stats(
    QMainWindow, Ui_MainWindow):

    def __init__(self):
        # 从文件中加载UI定义
        super(Stats, self).__init__()
        # 从 UI 定义中动态 创建一个相应的窗口对象
        # 注意：里面的控件对象也成为窗口对象的属性了
        # 比如 self.ui.button , self.ui.textEdit
        # self.ui = QUiLoader().load('main.ui')
        # self.ui = QUiLoader().load('main.ui')
        self.setupUi(self)
        # self.ui.button.clicked.connect(self.handleCalc)
        self.send.clicked.connect(self.handleCalc)

    def handleCalc(self):
        info = self.lineEdit.text()
        r = requests.get(info)
        r.encoding = "utf-8"
        text = r.text
        self.responseHeader.setPlainText("\n".join([f"{k}: {v}" for k,v in r.headers.items()]))
        self.responseText.setPlainText(text)
        # QMessageBox.about(self,
        #                   '统计结果',
        #                   info
        #                   )

app = QApplication()
stats = Stats()
stats.show()
app.exec()
